'==============================================================================
' LANG		: VBScript 
' NAME		: FCS-SampleScript Uninstall Symantec AV.vbs 
' VERSION	: 1.0003 3/2/2007
' Description 	: Script to uninstall Symantec AV components   
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
' Copyright (C) 2007. Microsoft Corporation.  All rights reserved.
'
' NOTES		: ALL SAMPLE SCRIPTS BEGIN WITH THE SAME SETUP ELEMENTS
'                 You can use this script standalone or incoporate the 
'                 subroutines in this script into a larger script.
'==============================================================================
Option Explicit
Dim bDEBUG : bDEBUG=False 'Set to TRUE to help with script debugging.
' Constants Declarations
  Const WAIT_ON_RETURN = True
  Const DO_NOT_WAIT_ON_RETURN = False
  Const HIDE_WINDOW = 0
  Const SHOW_WINDOW = 1
  Const ThisComputer = "."
  '==========================================================
' Main Routine
  On Error Resume Next
  If bDEBUG then On Error Goto 0
  
' Create system objects
  Dim WshShell      : Set WshShell = WScript.CreateObject("WScript.Shell")
  Dim objRegistry   : Set objRegistry = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
			                            ThisComputer & "\root\default:StdRegProv")
  Dim objWMIService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
                                                     ThisComputer & "\root\cimv2")

' Call the installation functions
  'Call FCS_InstallXPSP2Hotfix
  Call UninstallSymantecAV

' Clean out the Symantec Quarantine folder
' NOTE: If the uninstall process does not delete the quarantine directory
'       you will need to put the correct path in the erase command below
  On Error Resume Next
  'WshShell.Run "erase /F /S /Q C:\VIRUS\*.*",HIDE_WINDOW,WAIT_ON_RETURN
  If bDEBUG Then On Error Goto 0
  
' Clean up objects and exit
  Set objWMIService = Nothing
  Set objRegistry = Nothing
  Set WshShell = Nothing
  
  wscript.quit
  
'=====================================================================================
' SubRoutine UninstallSymantecAV
'       This routine uninstalls the Symantec AV clients
'
'  INPUTS: None
'  OUTPUT: Logs MSI uninstall event
' ASSUMES: The existence of the WshShell, objRegistry, and objWMIService objects
'	   MsiExec.exe is in the directory the script was executed from or in the
'          file search PATH
'   NOTES: This script is set to uninstall Symantec AV products using the registry.
'          Norton versions are included as well.
'          Uninstall by product GUID options are also included.
'          Pick the method that works best for your AV deployment.
'======================================================================================
  Private Sub UninstallSymantecAV

    Const SymantecDisplayName = "Symantec Antivirus"
    If bDEBUG then wscript.echo "DEBUG: Uninstalling Symantec Antivirus client"
    Call RegBasedUninstall(SymantecDisplayName)

  ' The following commands can be used to uninstall various versions of Norton Antivirus
  
  ' Any Norton Antivirus Version except 2004 Professional
    Const NortonDisplayName = "Norton Antivirus"
    'Call RegBasedUninstall(NortonDisplayName)

    On Error Resume Next
  ' Norton Antivirus 2004, 2005 & 2006
    'WshShell.Run"MsiExec /X{C6F5B6CF-609C-428E-876F-CA83176C021B} /q Reboot=""ReallySuppress""",HIDE_WINDOW,WAIT_ON_RETURN
    'WshShell.LogEvent 4, "Uninstalled Norton Antivirus 2006"

  ' Norton Antivirus 2004 Professional
    'WshShell.Run"C:\Program Files\Common Files\Symantec Shared\SymSetup\{C6B28661-7910-442E-ADDD-72EAA8395380}.exe /X",HIDE_WINDOW,WAIT_ON_RETURN
    'WshShell.LogEvent 4, "Norton Antivirus 2004 Professional"

    If bDEBUG Then On Error Goto 0

   ' Symantec LiveUpdate agent
   Const SymantecUpdateName = "LiveUpdate 3.2"
   Call RegBasedUninstall(SymantecUpdateName)
  	
 End Sub

'=====================================================================================
' SubRoutine RegBasedUninstall
'       This routine uninstall applications using the parameters supplied in the 
'       SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall registry key
'       
'  INPUTS: The display name of the application to be uninstalled
'  OUTPUT: Logs MSI uninstall events
' ASSUMES: The existence of the WshShell and objRegistry objects
'          MsiExec.exe is in the directory the script was executed from or in the
'          file search PATH
'
' READ THESE NOTES!
'   NOTES: This script fairly generic and can be used to uninstall any product
'          if you know the display name string. HOWEVER it assumes the use of MSI for 
'          all uninstalls.  If the application does not use MSI the routine will fail.

' CAUTION: This routine uses the InStr() function to locate the input display name in  
'          the registry display name. It does not do a direct match. Passing a poorly 
'          formed parameter to this routine could have some bad unintended consequences. 
'	   For example, if you pass the letter a to this routine it will uninstall 
'	   every product on the system with an "a" in the name!
'======================================================================================
Sub RegBasedUninstall(InputDisplayName)
   
   Const HKEY_LOCAL_MACHINE = &H80000002
   Const UninstallRegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
  
   Dim SubKeyArray, SubKey, DisplayName, UninstallString, StartPtr
   objRegistry.EnumKey HKEY_LOCAL_MACHINE, UninstallRegKey, SubKeyArray
 
   For Each SubKey In SubKeyArray
 	'Get the Display Name for this product
 	objRegistry.GetStringValue HKEY_LOCAL_MACHINE, UninstallRegKey & "\" & SubKey, "DisplayName", DisplayName

If bDEBUG Then wscript.echo "DEBUG: Uninstall Display name is: " & DisplayName

   	If Instr(DisplayName, InputDisplayName) > 0 Then 
		' Add the automatic, silent and no reboot MSI uninstall options
		objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
 			UninstallRegKey & "\" & SubKey, "UninstallString", UninstallString
 		
 		StartPtr = Instr(1,UninstallString,"/I") + 2
 		If StartPtr > 2 Then
 		   UninstallString = "MsiExec /X " & mid(UninstallString, StartPtr, 38) &_
 		                     " /q Reboot=""ReallySuppress"""
 		
 		Else
 		   UninstallString = UninstallString & " /q Reboot=""ReallySuppress"""
 		End If

If bDEBUG Then wscript.echo "DEBUG: Uninstall string is: " & UninstallString

' 		WshShell.Run UninstallString,HIDE_WINDOW,WAIT_ON_RETURN
 		WshShell.LogEvent 4, "Uninstalled " & DisplayName
 	End if
 	
   Next
End Sub